package com.gxa.controller.ly.systemManagement;

import com.github.pagehelper.PageInfo;
import com.gxa.common.R;
import com.gxa.entity.SysCourierCompany;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


@Api(value = "快递公司",tags = "快递公司接口API")
@Controller
@RequiresRoles(value = {"超级管理员","院长"},logical = Logical.OR)
@RequestMapping("/systemManagement/courierCompany")
public class CourierCompanyController {
    /**
     * 查找快递公司所有接口
     * @param currentPage 当前页
     * @param pageSize 每页条数
     * @return JSON
     */
    @RequestMapping(value = "/findCompanyList",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查找所有快递公司接口",notes = "查找所有快递公司",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页数", paramType = "query", dataType = "String", required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findCompanyList(Integer currentPage,Integer pageSize) {

        R r = new R<>();

        SysCourierCompany sysCourierCompany = new SysCourierCompany();
        sysCourierCompany.setName("有限抄作业公司");
        sysCourierCompany.setCode("250");
        sysCourierCompany.setUrl("www.czy.com");
        sysCourierCompany.setFirstCost(BigDecimal.valueOf(9.9));
        sysCourierCompany.setEnable(0);

        SysCourierCompany sysCourierCompany1 = new SysCourierCompany();
        sysCourierCompany1.setName("有限打群架公司");
        sysCourierCompany1.setCode("9527");
        sysCourierCompany1.setUrl("www.dqj.com");
        sysCourierCompany1.setFirstCost(BigDecimal.valueOf(99.99));
        sysCourierCompany1.setEnable(1);

        List<SysCourierCompany> list = new ArrayList<>();
        list.add(sysCourierCompany);
        list.add(sysCourierCompany1);

        PageInfo pageInfo = new PageInfo(list);
        r.setMsg("success");
        r.setCode(200);
        r.setData(pageInfo);
        return r;
    }


    /**
     * 添加快递公司接口
     * @param sysCourierCompany 菜单对象
     * @return 影响行数
     */
    @RequestMapping(value = "/addCompany",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加快递公司接口",notes = "添加快递公司",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addCompany(@RequestBody @ApiParam(name = "sysCourierCompany",value = "快递公司对象",required = true) SysCourierCompany sysCourierCompany) {
        R r = new R<>();
        if (sysCourierCompany != null) {
            return R.ok();
        }else {
            r.setCode(500);
            r.setMsg("添加失败");
        }
        return r;
    }

    /**
     * 删除快递公司
     * @param id 菜单id
     * @return 影响行数或失败
     */
    @RequestMapping(value = "/delCompany",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除快递公司接口",notes = "删除快递公司",httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "id", value = "快递公司id", paramType = "query", dataType = "String", required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R delCompany(Integer id) {
        R r = new R<>();
        if (id != null && id >=0) {
            return R.ok();
        }
        return r;
    }

    /**
     * 更新快递公司接口
     * @param sysCourierCompany 需要修改的对象
     * @return 返回是否成功
     */
    @RequestMapping(value = "/updateMenu",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "更新快递公司接口",notes = "更新快递公司",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateMenu(@RequestBody  @ApiParam(name = "sysCourierCompany",value = "快递公司对象",required = true) SysCourierCompany sysCourierCompany) {
        R r = new R<>();
        if (sysCourierCompany != null) {
            return R.ok();
        }else {
            r.setCode(400);
            r.setMsg("添加失败");
        }
        return r;
    }
}
